﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CSharpWin;
using EMR.EditorUtility;
using DBUtility;

namespace DoctorWorkstationManage
{
    public partial class SaveAsForm : SkinForm
    {
        string diseaseName;
        string title;
        DBEmr.BLL.MR_TEMPLET_INDEX bll_MR_TEMPLET_INDEX;
        DBEmr.Model.MR_TEMPLET_INDEX model_MR_TEMPLET_INDEX;
        public SaveAsForm()
        {
            InitializeComponent();
        }

        public SaveAsForm(string title1, string disease, DBEmr.Model.MR_TEMPLET_INDEX model_MR_TEMPLET_INDEX_tmp)
            : this()
        {
            bll_MR_TEMPLET_INDEX = new DBEmr.BLL.MR_TEMPLET_INDEX();
            model_MR_TEMPLET_INDEX = model_MR_TEMPLET_INDEX_tmp;
            title = title1.Trim();
            diseaseName = disease.Trim();
            this.StartPosition = FormStartPosition.CenterScreen;
        }


        private void simpleButtonExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void Save()
        {
            try
            {
                if (model_MR_TEMPLET_INDEX == null) return;

                if (checkBoxPersonal.Checked)
                {
                    model_MR_TEMPLET_INDEX.Template_type = 1;//个人模板
                }
                else 
                {
                    model_MR_TEMPLET_INDEX.Template_type = 0;//科室模板
                    model_MR_TEMPLET_INDEX.DEPT_CODE = Set.STRING_DEP_ID;
                }
                model_MR_TEMPLET_INDEX.TOPIC = textBoxTitle.Text;
                model_MR_TEMPLET_INDEX.MR_ATTR = textBoxDisease.Text;
                bll_MR_TEMPLET_INDEX.Add(model_MR_TEMPLET_INDEX);
                
                MessageBox.Show("保存成功！");
                //m_app.CustomMessageBox.MessageShow("保存成功！");
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("保存失败！");
                MessageException.WriteErorrLog(ex);
                //m_app.CustomMessageBox.MessageShow("保存失败！" + ex.Message);
            }
        }

        private void SaveAsForm_Load(object sender, EventArgs e)
        {
            InitForm();
        }

        private void InitForm()
        {
            textBoxTitle.Text = title;
            textBoxDisease.Text = diseaseName;
            //textBoxDisease.Text = m_RecordDal.GetCatalog(m_Model.ModelCatalog);
        }

        private void checkBoxPersonal_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBoxPersonal.Checked)
            {
                checkBoxDepartment.Checked = false;
            }
            else
            {
                checkBoxDepartment.Checked = true;
            }
        }

        private void checkBoxDepartment_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBoxDepartment.Checked)
            {
                checkBoxPersonal.Checked = false;
            }
            else
            {
                checkBoxPersonal.Checked = true;
            }
        }

        private void buttonAbout_Click(object sender, EventArgs e)
        {
            Save();
        }

        private void buttonExExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}